package com.abigdreamer.im.server.module.msgProcess;

import java.util.ArrayList;
import java.util.List;

import com.abigdreamer.im.message.BaseMessage;
import com.abigdreamer.im.message.TalkMessage;
import com.abigdreamer.im.server.module.ServerCache;
import com.abigdreamer.im.server.module.UserConnect;

public class TalkMessageProcess implements IMessageProcess {

	public void processMessage(BaseMessage message) {
		TalkMessage talkMessage = (TalkMessage) message;
		String destQQ = talkMessage.getDestQQ();
		ServerCache cache = ServerCache.getInstance();
		UserConnect userConnect = cache.getUserConnectMap().get(destQQ);
		if (userConnect != null) {
			userConnect.sendTextMessage(talkMessage);
		} else {
			List<BaseMessage> leaveMsgList = cache.getAllLeaveMessageMap().get(destQQ);
			if (leaveMsgList == null) {
				leaveMsgList = new ArrayList<BaseMessage>();
			}
			leaveMsgList.add(talkMessage);
			cache.getAllLeaveMessageMap().put(destQQ, leaveMsgList);
		}
	}

}
